/**
 * mysql 连接配置
 */
const Sequelize = require('sequelize')
const { mySqlConfig } = require('../config')
const Op = Sequelize.Op;
const operatorsAliases = {
  $eq: Op.eq,
  $ne: Op.ne,
  $gte: Op.gte,
  $gt: Op.gt,
  $lte: Op.lte,
  $lt: Op.lt,
  $not: Op.not,
  $in: Op.in,
  $notIn: Op.notIn,
  $is: Op.is,
  $like: Op.like,
  $notLike: Op.notLike,
  $iLike: Op.iLike,
  $notILike: Op.notILike,
  $regexp: Op.regexp,
  $notRegexp: Op.notRegexp,
  $iRegexp: Op.iRegexp,
  $notIRegexp: Op.notIRegexp,
  $between: Op.between,
  $notBetween: Op.notBetween,
  $overlap: Op.overlap,
  $contains: Op.contains,
  $contained: Op.contained,
  $adjacent: Op.adjacent,
  $strictLeft: Op.strictLeft,
  $strictRight: Op.strictRight,
  $noExtendRight: Op.noExtendRight,
  $noExtendLeft: Op.noExtendLeft,
  $and: Op.and,
  $or: Op.or,
  $any: Op.any,
  $all: Op.all,
  $values: Op.values,
  $col: Op.col
}
// console.log(mySqlConfig)
const sequelize = new Sequelize(mySqlConfig.database, mySqlConfig.user, mySqlConfig.password, {
  host: mySqlConfig.host,
  dialect: 'mysql',
  pool: {
    max: 10,
    min: 0,
    idle: 10000
  },
  define: {
    timestamps: true,
    paranoid: true,
    createdAt: 'created_time',
    updatedAt: 'updated_time',
    deletedAt: 'deleted_time',
    underscored: true,
  },
  query: { raw: true },
  // 添加这个配置 
  dialectOptions: {
    dateStrings: true,
    typeCast: true,

  },
  timezone: '+08:00',
  operatorsAliases: operatorsAliases
})

// sequelize.authenticate().then(() => {
//   console.log('mysql success')
// }).catch(err => {
//   console.log('mysql error', err)
// })

module.exports = sequelize